
import './fab_with_icons.dart';
import './layout.dart';
import 'package:flutter/material.dart';

import 'anchor_bar.dart';
import 'page/extension_page.dart';
import 'page/message_page.dart';
import 'page/news_page.dart';
import 'page/video_page.dart';

main() =>
    runApp(MaterialApp(debugShowCheckedModeBanner: false, home: HomePage()));

class HomePage extends StatefulWidget {
  @override
  createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
  var _currentNav = 0;
  get icons => [Icons.sms, Icons.mail, Icons.phone];

  get _getNavItemsBTM => [
        NavItemBTM(iconData: Icons.menu, text: '首页'),
        NavItemBTM(iconData: Icons.layers, text: '视频'),
        NavItemBTM(iconData: Icons.dashboard, text: '拓展'),
        NavItemBTM(iconData: Icons.info, text: '消息'),
      ];
  @override
  build(context) => Scaffold(
        body: _skipPage(_currentNav),
        bottomNavigationBar: AnchorBar(
          color: Colors.grey,
          selectedColor: Colors.red,
          notchedShape: CircularNotchedRectangle(),
          onTabSelected: (index) => setState(() => _currentNav = index),
          items: _getNavItemsBTM,
        ),
        floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
        floatingActionButton: _buildFab(context),
      );

  Widget _buildFab(BuildContext context) {
    return AnchoredOverlay(
      showOverlay: true,
      overlayBuilder: (context, offset) {
        return CenterAbout(
          position: Offset(offset.dx, offset.dy - icons.length * 35.0),
          child: FloatIcons(
            icons: icons,
            onIconTapped: (index) => setState(() => _currentNav = index),
          ),
        );
      },
      child: FloatingActionButton(
        onPressed: () {},
        tooltip: 'wafdasf',
        child: Icon(Icons.add),
      ),
    );
  }

    _skipPage(index) {
      switch (index) {
        case 0:
          return NewsPage();
        case 1:
          return VideoPage();
        case 2:
          return ExtensionPage();
        case 3:
          return MessagePage();
        default:
          return NewsPage();
      }
    }
}
